import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-11-05
 * Time: 20:40
 */
class Student {
    public String name;
    public int id;

    public Student(String name, int id) {
        this.name = name;
        this.id = id;
    }
}
public class Test {
    //5.前K个高频单词
    public List<String> topKFrequent(String[] words, int k) {
        HashMap<String,Integer> hashMap = new HashMap<>();
        //1.统计每个单词的个数
        for(String word : words) {
            if(hashMap.containsKey(word)){
                int val = hashMap.get(word);
                hashMap.put(word,val+1);
            }else {
                hashMap.put(word,1);
            }
        }
        //2.创建小跟堆，存放key-value键值对
        PriorityQueue<Map.Entry<String,Integer>> minHeap;
        minHeap = new PriorityQueue<>(new Comparator<Map.Entry<String,Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                if (o1.getValue().compareTo(o2.getValue()) == 0) {
                    return o2.getKey().compareTo(o1.getKey());//大根堆--频率相同，为了使逆置后打印出来是字母小的先打印
                }
                return o1.getValue().compareTo(o2.getValue());//小跟堆--栈顶是堆中的最小元素，逆置后先打印的是频率最高的
            }
        });
        //3.遍历
        for(Map.Entry<String,Integer> entry : hashMap.entrySet()) {
            if(minHeap.size() < k) {
                minHeap.offer(entry);
            }else {
                Map.Entry<String,Integer> top = minHeap.peek();
                if(top.getValue().compareTo(entry.getValue()) < 0) {
                    minHeap.poll();
                    minHeap.add(entry);
                }else if(top.getValue().compareTo(entry.getValue()) == 0) {
                    if(top.getKey().compareTo(entry.getKey()) > 0) {
                        minHeap.poll();
                        minHeap.add(entry);
                    }
                }
            }
        }
        //4.放入链表，逆置
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < k; i++) {
            Map.Entry<String,Integer> tmp = minHeap.poll();
            arrayList.add(tmp.getKey());
        }
        Collections.reverse(arrayList);
        return arrayList;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str1 = in.nextLine();
            String str2 = in.nextLine();
            getError(str1,str2);
        }
    }
    //4.坏键盘打字
    private static void getError(String str1,String str2) {
        str1 = str1.toUpperCase();
        str2 = str2.toUpperCase();
        Set<Character> actSet = new HashSet<>();
        for(int i = 0;i < str2.length();i++) {
            char ch = str2.charAt(i);
            actSet.add(ch);
        }
        Set<Character> setBroke = new HashSet<>();
        for(int i = 0;i < str1.length();i++) {
            char ch = str1.charAt(i);
            if(!actSet.contains(ch)&&!setBroke.contains(ch)) {
                setBroke.add(ch);
                System.out.print(ch);
            }
        }
    }
    //3.宝石与石头
    public int numJewelsInStones(String jewels, String stones) {
        Set<Character> set = new HashSet<>();
        for(int i = 0;i < jewels.length();i++) {
            char ch = jewels.charAt(i);
            set.add(ch);
        }
        int count = 0;
        for(int i = 0;i < stones.length();i++) {
            char ch = stones.charAt(i);
            if(set.contains(ch)) {
                count++;
            }
        }
        return count;
    }
    class Node {
        int val;
        Node next;
        Node random;

        public Node(int val) {
            this.val = val;
            this.next = null;
            this.random = null;
        }
    }
    //2.复制带随机指针的链表
    public Node copyRandomList(Node head) {
        Map<Node,Node> map = new HashMap<>();
        Node cur = head;
        //1.现将现将原链表的节点放入map中，再将原链表的值拷贝到新链表当中放入map中
        //使原链表和新链表对应的节点形成key-value型的键值对映射关系
        while(cur != null) {
            Node node = new Node(cur.val);
            map.put(cur,node);
            cur = cur.next;
        }
        cur = head;
        //2.再将原节点的nextherandom通过映射的关系，拷贝到新的节点上
        while(cur != null) {
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        //此时复制链表中的指针都不应指向原链表中的节点,返回新链表的头结点
        return map.get(head);
    }
    //1.只出现一次的数字
    public int singleNumber(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i < nums.length;i++) {
            if(map.containsKey(nums[i])) {
                map.remove(nums[i]);
            }else {
                map.put(nums[i],1);
            }
        }
        for(int i = 0;i < nums.length;i++) {
            if(map.containsKey(nums[i])) {
                return nums[i];
            }
        }
        return -1;
    }
    public static void main3(String[] args) {
        //统计一篇英文阅读 每个单词出现的次数
        String[] words = {"red","blue","green","blue","green","yellow","green"};
        Map<String,Integer> map = countWord(words);
        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> entry : entrySet) {
            System.out.println("key: " + entry.getKey() + " val: " + entry.getValue());
        }
    }

    private static Map<String, Integer> countWord(String[] words) {
        Map<String,Integer> map = new HashMap<>();
        for(String word : words) {
            if(map.containsKey(word)) {
                int count = map.get(word);
                map.put(word, count+1);
            }else {
                map.put(word,1);
            }
        }
        return map;
    }

    public static void main2(String[] args) {
        //泛型哈希桶
        Student student1 = new Student("zhangsan",2022);
        Student student2 = new Student("lisi",2021);
        Student student3 = new Student("wangwu",2023);
        Student student4 = new Student("laowang",2027);

        HashBuck2<Student,String> hashBuck = new HashBuck2<>();
        hashBuck.push(student1,"20001");
        hashBuck.push(student2,"20002");
        hashBuck.push(student3,"20003");
        hashBuck.push(student3,"20005");
        hashBuck.push(student4,"20007");
        System.out.println(hashBuck.getVal(student2));
    }
    public static void main1(String[] args) {
        //整型哈希桶
        HashBuck hashBuck = new HashBuck();
        hashBuck.push(12,1212);
        hashBuck.push(13,1313);
        hashBuck.push(14,1414);
        hashBuck.push(2,22);
        hashBuck.push(3,33);
        hashBuck.push(12,999);
        hashBuck.push(24,2424);
        hashBuck.push(73,7373);
        hashBuck.push(32,3232);
        int getVal = hashBuck.getVal(12);
        System.out.println(getVal);
    }
}
